package com.cheetah.start.common.interceptor;

import com.cheetah.start.common.exception.CheetahException;
import com.cheetah.start.module.system.service.ISysSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 接口文档拦截器
 *
 * @author xjh
 * @date 2022/03/28
 */
@Component
public class SwaggerInterceptor implements HandlerInterceptor {

    @Autowired
    private ISysSetService ISysSetService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean b = ISysSetService.allowSwagger();
        if (!b) {
            throw new CheetahException("接口文档禁用");
        }
        return true;
    }
}
